package org.taohuawu.servicer.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.taohuawu.pojo.Item;
import org.taohuawu.service.ItemService;

import java.util.*;

@Slf4j
@Service
public class ItemServiceImpl implements ItemService {

    private static List<Item> itemList = new ArrayList<>();

    static {
        itemList.add(new Item(1, "商品一", 100));
        itemList.add(new Item(2, "商品二", 120));
        itemList.add(new Item(3, "商品三", 140));
        itemList.add(new Item(4, "商品四", 160));
        itemList.add(new Item(5, "商品五", 180));
        itemList.add(new Item(6, "商品六", 190));
    }

    @Override
    public List<Item> getItems(String orderId) {
        return itemList;
    }

    @Override
    public void decreaseNumbers(List<Item> list) {
        if (list != null && list.size() > 0) {
            for (Item item : list) {
                Item resource = itemList.get(item.getId() - 1);
                resource.setNumber(resource.getNumber() - 1);
                log.info(resource.getName() + " -- 减少库存 -- ，剩余库存：" + resource.getNumber());
            }
        }
    }
}
